home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Guitar / dcblock.asm < prev    next >
Encoding:
Assembly Source File  |  1992-07-28  |  5.1 KB  |  130 lines

  1. ;;  Author - Rick Vander Kam
  2. ;;  Copyright (c) 1992 - All rights reserved
  3. ;;  Modification history
  4. ;;  --------------------
  5. ;;  2/29/92/rvk - initial file created from /usr/lib/dsp/ugsrc/fir3.asm
  6. ;;
  7. ;;------------------------------ DOCUMENTATION ---------------------------
  8. ;;  NAME
  9. ;;      dcblock (UG macro) - "dc notch" filter section
  10. ;;
  11. ;;  SYNOPSIS
  12. ;;      dcblock pf,ic,sout,aout0,sinp,ainp0,so10,si10,bb00,bb10,aa10
  13. ;;
  14. ;;  MACRO ARGUMENTS
  15. ;;      pf        = global label prefix (any text unique to invoking macro)
  16. ;;      ic        = instance count (s.t. pf\_dcblock_\ic\_ is globally unique)
  17. ;;      sout      = output vector memory space ('x' or 'y')
  18. ;;      aout0     = initial output vector memory address
  19. ;;      sinp      = input vector memory space ('x' or 'y')
  20. ;;      ainp0     = initial input vector memory address
  21. ;;      bb00      = initial coefficient of undelayed input
  22. ;;      bb10      = initial coefficient of once delayed input
  23. ;;      aa10      = initial coefficient of once delayed output
  24. ;;      so10        = initial once delayed output state variable
  25. ;;      si10        = initial once delayed input state variable
  26. ;;
  27. ;;  DSP MEMORY ARGUMENTS
  28. ;;      Access         Description              Initialization
  29. ;;      ------         -----------              --------------
  30. ;;      x:(R_X)+       Current output address   aout0
  31. ;;      x:(R_X)+       Current input address    ainp0
  32. ;;      x:(R_X)+       aa1 coefficient         aa10
  33. ;;      x:(R_X)+       so1 state variable         so10
  34. ;;      y:(R_Y)+       bb0 coefficient          bb00
  35. ;;      y:(R_Y)+       bb1 coefficient          bb10
  36. ;;      y:(R_Y)+       si1 state variable          si10
  37. ;;
  38. ;;  DESCRIPTION
  39. ;;      The dcblock unit-generator implements a one-pole,
  40. ;;      one-zero filter section in direct form.  For best performance,
  41. ;;      output memory space should be y.
  42. ;;
  43. ;;      In pseudo-C notation:
  44. ;;
  45. ;;      ainp = x:(R_X)+;
  46. ;;      aout = x:(R_X)+;
  47. ;;      aa1 = x:(R_X)+;
  48. ;;      so1 = x:(R_X)+;
  49. ;;      bb0 = y:(R_Y)+;
  50. ;;      bb1 = y:(R_Y)+;
  51. ;;      si1 = y:(R_Y)+;
  52. ;;
  53. ;;      for (n=0;n<I_NTICK;n++) {
  54. ;;           in = sinp:ainp[n];
  55. ;;           output = sout:aout[n] = bb0*in + bb1*si1 + aa1*so1;
  56. ;;           si1 = in;
  57. ;;           so1 = output;
  58. ;;      }
  59. ;;        
  60. ;;  DSPWRAP ARGUMENT INFO
  61. ;;      dcblock (prefix)pf,(instance)ic,(dspace)sout,(output)aout,
  62. ;;         (dspace)sinp,(input)ainp,so1,si1,bb0,bb1,aa1
  63. ;;
  64. ;;  MAXIMUM EXECUTION TIME
  65. ;;      ???
  66. ;;
  67. ;;  MINIMUM EXECUTION TIME
  68. ;;       ???
  69. ;;
  70. ;;  SOURCE
  71. ;;      /user/rvk/ee265/test/dcblockUG/dcblock.asm
  72. ;;
  73. ;;  SEE ALSO
  74. ;;      /usr/lib/dsp/ugsrc/biquad.asm  - two-pole, two-zero filter section
  75. ;;      /usr/lib/dsp/ugsrc/onepole.asm - one-pole filter section
  76. ;;      /usr/lib/dsp/ugsrc/twopole.asm - two-pole filter section
  77. ;;
  78. ;;  ALU REGISTER USE
  79. ;;      X0 = y(n-1)  = so1 = once delayed output
  80. ;;      X1 = x(n), x(n-1) = in, si1 = undelayed and once-delayed input
  81. ;;      Y0 = bb0,aa1 = undelayed and once-delayed output signal coefficients
  82. ;;      Y1 = bb1 = once-delayed signal coefficient
  83. ;;       A = multiply-add accumulator
  84. ;;       B = holder for bb0
  85. ;;
  86. dcblock   macro pf,ic,sout,aout0,sinp,ainp0,so10,si10,bb00,bb10,aa10
  87.                new_xarg pf\_dcblock_\ic\_,aout,aout0   ; output address arg
  88.                new_xarg pf\_dcblock_\ic\_,ainp,ainp0   ; input address arg
  89.                new_xarg pf\_dcblock_\ic\_,aa1,aa10    ; once delayed output coeff
  90.                new_xarg pf\_dcblock_\ic\_,si1,si10    ; once delayed input sample
  91.                new_yarg pf\_dcblock_\ic\_,bb0,bb00     ; undelayed input coeff
  92.                new_yarg pf\_dcblock_\ic\_,bb1,bb10     ; once-delayed input coeff
  93.                new_yarg pf\_dcblock_\ic\_,so1,so10     ; once-delayed output
  94.  
  95.                move x:(R_X)+,R_O                  ; output address to R_O
  96.                move x:(R_X)+,R_I1                 ; input address to R_I1
  97.  
  98.                move x:(R_X)+,Y0        ;aa1 to Y0
  99.            move x:(R_X),X1 y:(R_Y)+,B        ; si1 to X1, bb0 to B
  100.                move y:(R_Y)+,Y1                   ; bb1 to Y1
  101.                move y:(R_Y),X0                    ; so1 to X0
  102.                mpy  X1,Y1,A                        ; A = si1*bb1
  103.                macr X0,Y0,A   sinp:(R_I1)+,X1   ; A += so1*aa1, update si1=x(n)
  104.            tfr Y0,B  B,Y0            ;bb0 to Y0, aa1 to B (swap)
  105.            macr X1,Y0,A            ;A += bb0*x(n) (= first output)
  106.                do #I_NTICK-1,pf\_dcblock_\ic\_tickloop
  107.                    if "sout"=='y'
  108.                move A,X0 A,sout:(R_O)+
  109.             else
  110.                 move A,X0                ;update so1
  111.             move A,sout:(R_O)+        ;ship output
  112.             endif
  113.             tfr Y0,B B,Y0                          ;bb0 to B, aa1 to Y0
  114.                     mpy  X1,Y1,A                             ;A=bb1*x(n-1)
  115.                     macr X0,Y0,A   sinp:(R_I1)+,X1    ;A+=aa1*y(n-1),  si1=x(n)
  116.             tfr Y0,B  B,Y0                      ;bb0 to Y0, aa1 to B (swap)
  117.             macr X1,Y0,A                      ;A += bb0*x(n)
  118. pf\_dcblock_\ic\_tickloop    
  119.                if "sout"=='y'
  120.                     move X1,x:(R_X)+    A,sout:(R_O)+
  121.             move A,y:(R_Y)+
  122.                else
  123.                     move A,sout:(R_O)+       ; ship last output
  124.                     move X1,x:(R_X)+         ; save si2 in mem arg
  125.             move A,y:(R_Y)+       ; save so1 in mem arg
  126.                endif
  127.      endm
  128.  
  129.  
  130.